<template>
	<div>
		<v-header :headerLeftText="leftText" :headerCenterText="headerText"></v-header>

		<div class="bank_info_content f_size24">
			<div class="b_row" style="margin-bottom: 10px;">
				<span>持卡人姓名：</span>
				<input v-model="accountName" type="text" placeholder="真实姓名，设置成功无法修改" />
			</div>
			<div class="b_row">
				<span>开&nbsp;户&nbsp;银&nbsp;行：</span>
				<input v-model="bankName" type="text" placeholder="请输入开户银行的名称" />
			</div>
			<div class="b_row">
				<span>开&nbsp;户&nbsp;网&nbsp;点：</span>
				<input v-model="branchName" type="text" placeholder="请输入开户银行的详细网点地址" />
			</div>
			<div class="b_row">
				<span>银&nbsp;行&nbsp;卡&nbsp;号：</span>
				<input v-model="bankCard" type="text" placeholder="银行卡号" />
			</div>

			<div class="t_row" style="margin-top: 50px;">
				<div class="button_row">
					<button @click="addBankInfo">保存</button>
				</div>
			</div>
		</div>

	</div>
</template>
<script>
	import { Toast } from 'mint-ui';
	export default {
		created() {
			this.$api.get('/front/banks', null, r => {
				console.log('银行卡信息r', r)
				if(r.data.dataCount === 0) {
					this.dataCount = 0
				} else {
					this.dataCount = 1
				}
				this.accountName = r.data.list[0].accountName
				this.bankCard = r.data.list[0].bankCard
				this.bankName = r.data.list[0].bankName
				this.branchName = r.data.list[0].branchName
				this.bankId = r.data.list[0].bankId
			})
		},
		data() {
			return {
				leftText: '',
				headerText: '银行卡信息',
				accountName: '',
				bankCard: '',
				bankName: '',
				branchName: '',
				bankId: '',
				dataCount: 0
			}
		},
		methods: {
			addBankInfo: function() {
				var self = this
				if(self.dataCount === 0) {
					this.$api.post('/front/banks/' + this.bankId, {
						accountName: this.accountName,
						bankCard: this.bankCard,
						bankName: this.bankName,
						branchName: this.branchName
					}, r => {
						console.log('天津银行卡信息r', r)
						if(r.code == 400) {
							Toast(r.error)
						} else {
							Toast(r.data)
							setTimeout(function(){
								self.$router.go(-1)
							}, 1500)
						}
					})
				} else {
					this.$api.put('/front/banks/' + this.bankId, {
						accountName: this.accountName,
						bankCard: this.bankCard,
						bankName: this.bankName,
						branchName: this.branchName
					}, r => {
						console.log('天津银行卡信息r', r)
						if(r.code == 400) {
							Toast(r.error)
						} else {
							Toast(r.data)
							setTimeout(function(){
								self.$router.go(-1)
							}, 1500)
						}
					})
				}
			}

		}
	}
</script>

<style>

</style>